home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fatted Calf
/
The Fatted Calf.iso
/
Applications
/
Games
/
NeXTmj
/
Source
/
TileCountManager.cc
< prev
next >
Wrap
Text File
|
1991-03-17
|
1KB
|
105 lines
/*
*
$Author$
$Header$
*
$Log$
*/
#import "TileCountManager.h"
extern "C" {
#import <assert.h>
#import <math.h>
}
// This is the number of digits that
// are to be maintained in the count view.
#define NUMBER_OF_DIGITS 3
TileCountManager::TileCountManager( TileCountView* view ) {
assert( view );
my_view = view;
[ my_view setNeedsDisplay:YES ];
count_value = NUMBER_OF_TILES;
}
void TileCountManager::updateView( void ) {
[[ my_view setNeedsDisplay:YES ] display ];
}
void TileCountManager::resetCount( void ) {
count_value = NUMBER_OF_TILES;
updateView();
}
void TileCountManager::addTwo( void ) {
count_value += 2;
assert( count_value < NUMBER_OF_TILES );
updateView();
}
void TileCountManager::subtractTwo( void ) {
count_value -= 2;
assert( count_value >= 0 );
updateView();
}
int TileCountManager::count( void ) {
return count_value;
}
BOOL TileCountManager::isEmpty( void ) {
return count_value == 0;
}
void TileCountManager::drawImage( void ) {
NXRect bounds;
int tmp_value = count(),
i;
assert([ my_view isFocusView ]);
[ my_view getBounds:&bounds ];
for( i = 0; i < NUMBER_OF_DIGITS; ++i ) {
int digit = tmp_value / ( int )pow( 10, ( NUMBER_OF_DIGITS - 1 - i ));
NXPoint p = { 0, 0 };
p.x = i * ( TILE_SIZE - TILE_SHIFT );
number_array[ digit ].drawImage( p );
tmp_value -= digit * ( int )pow( 10, ( NUMBER_OF_DIGITS - 1 - i ));
}
}